package org.hot100_3;

import java.util.ArrayList;
import java.util.List;

public class leetcode230 {
    public int kthSmallest(TreeNode root, int k) {

        List<Integer> list =new ArrayList<>();
        treeToList(root,list);

        return list.get(k-1);
    }

    private void treeToList(TreeNode root,List<Integer> list){
        if (root==null){
            return ;
        }

        treeToList(root.left,list);

        list.add(root.val);

        treeToList(root.right,list);
    }
}
